﻿package mortal.game.view.copy.petBreak
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.swfPlayer.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tooltip.tooltips.*;
    import mortal.game.view.common.tooltip.tooltips.data.*;
    import mortal.game.view.copy.petBreak.vo.*;
    import mortal.mvc.core.*;

    public class PetBreakCopyPointItem extends GSprite
    {
        private var _point:GImageBitmap;
        private var _data:TPetBreakConfig;
        private var _maxStar:int;
        private var _isActivate:Boolean;
        private var _enterBtn:GButton;
        private var _sweepBtn:GButton;
        private var _isLoadCompl:Boolean;
        private var _effectPlayer:SWFPlayer;

        public function PetBreakCopyPointItem()
        {
            this.buttonMode = true;
            return;
        }// end function

        private function onMouseOver(event:MouseEvent) : void
        {
            if (this.hasBreak)
            {
                return;
            }
            var _loc_2:* = this._enterBtn.y + this._enterBtn.height;
            this._enterBtn.visible = true;
            if (this._maxStar >= 3 && Cache.instance.copy.petBreakCopy.petBreakInfo.sweepTimes < PetBreakCopyUtil.maxSweepTimes)
            {
                this._sweepBtn.visible = true;
                _loc_2 = this._sweepBtn.y + this._sweepBtn.height;
            }
            this._point.filters = [FilterConst.guideTipsFilter];
            this.graphics.beginFill(16711935, 0);
            this.graphics.drawRect(this._enterBtn.x, 0, this._enterBtn.width, _loc_2);
            this.graphics.endFill();
            this.configEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }// end function

        private function onMouseOut(event:MouseEvent) : void
        {
            this._enterBtn.visible = false;
            this._sweepBtn.visible = false;
            this._point.filters = [];
            this.graphics.clear();
            this.removeEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }// end function

        private function onItemOper(event:MouseEvent) : void
        {
            var _loc_2:* = Cache.instance.copy.petBreakCopy;
            var _loc_3:* = new PetBreakCopyOperVo();
            _loc_3.floor = this._data.floor;
            _loc_3.level = this._data.pass;
            if (event.target == this._sweepBtn)
            {
                if (Cache.instance.copy.isInCopy)
                {
                    MsgManager.showRollTipsMsg(Language.getString(70352));
                    return;
                }
                if (_loc_2.petBreakInfo.hp + _loc_2.buffHp < 6)
                {
                    MsgManager.showFightTipsImpl(Language.getString(70349), MsgRollTipsType.msgRollTips6, true);
                    return;
                }
                _loc_3.type = PetBreakCopyUtil.SWEEP;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetBreakCopyPointItemOper, _loc_3));
            }
            else if (event.target == this._enterBtn)
            {
                if (Cache.instance.copy.isInCopy)
                {
                    MsgManager.showRollTipsMsg(Language.getString(70351));
                    return;
                }
                if (_loc_2.petBreakInfo.hp + _loc_2.buffHp < 6)
                {
                    MsgManager.showFightTipsImpl(Language.getString(70349), MsgRollTipsType.msgRollTips6, true);
                    return;
                }
                _loc_3.type = PetBreakCopyUtil.ENTER;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetBreakCopyEnter, _loc_3));
            }
            return;
        }// end function

        private function setToolTip() : void
        {
            var _loc_1:* = new ToolTipPetBreakCopyItemData();
            _loc_1.petBreak = this._data;
            _loc_1.star = this._maxStar;
            ToolTipsManager.unregister(this);
            ToolTipsManager.register(this, ToolTipPetBreakCopyItem, _loc_1);
            return;
        }// end function

        private function setEffectPost() : void
        {
            if (this._effectPlayer == null && this._isLoadCompl)
            {
                return;
            }
            var _loc_1:* = this._enterBtn.x + this._enterBtn.width / 2;
            var _loc_2:* = localToGlobal(new Point(_loc_1, -28));
            var _loc_3:* = this.parent.globalToLocal(_loc_2);
            this._effectPlayer.move(_loc_3.x, _loc_3.y);
            return;
        }// end function

        public function get hasBreak() : Boolean
        {
            return this._isActivate && this._data.isBig == EPetBreakType._EBreakSmallPass;
        }// end function

        public function setData(param1:TPetBreakConfig, param2:String) : void
        {
            this._data = param1;
            this.x = this._data.passIconX;
            this.y = this._data.passIconY;
            if (param1.isBig == EPetBreakType._EBreakBigPass)
            {
                var _loc_3:int = 0;
                this._point.y = 0;
                this._point.x = _loc_3;
                this._point.imgUrl = "petBigBreakBg_" + param2 + ".png";
            }
            else
            {
                var _loc_3:Number = -7.5;
                this._point.y = -7.5;
                this._point.x = _loc_3;
                this._point.bitmapData = GlobalClass.getBitmapData(ImagesConst.SmallRedPoint);
                this.onLoadCompl();
            }
            this.setToolTip();
            return;
        }// end function

        public function set maxStar(param1:int) : void
        {
            this._maxStar = param1;
            this.setToolTip();
            return;
        }// end function

        public function set isActivate(param1:Boolean) : void
        {
            this._isActivate = param1;
            if (this.hasBreak)
            {
                this._point.filters = [FilterConst.colorFilter];
                ToolTipsManager.unregister(this);
                ToolTipsManager.register(this, null, Language.getString(70337));
            }
            else
            {
                this._point.filters = null;
            }
            this.mouseEnabled = this._isActivate;
            return;
        }// end function

        public function set effectPlayer(param1:SWFPlayer) : void
        {
            this._effectPlayer = param1;
            this.mouseEnabled = true;
            this.setEffectPost();
            return;
        }// end function

        private function onLoadCompl() : void
        {
            this._isLoadCompl = true;
            if (this._enterBtn.width > this._point.width)
            {
                this._enterBtn.x = this._point.x - Math.abs(this._point.width - this._enterBtn.width) / 2;
                this._sweepBtn.x = this._point.x - Math.abs(this._point.width - this._enterBtn.width) / 2;
            }
            else
            {
                this._enterBtn.x = this._point.x + Math.abs(this._point.width - this._enterBtn.width) / 2;
                this._sweepBtn.x = this._point.x + Math.abs(this._point.width - this._enterBtn.width) / 2;
            }
            this._enterBtn.y = this._point.height;
            this._sweepBtn.y = this._point.height + 23;
            this.setEffectPost();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._point = UIFactory.gImageBitmap("", 0, 0, this, this.onLoadCompl);
            this._enterBtn = UIFactory.gButton(Language.getString(70335), -10, 10, 62, 22, this);
            this._sweepBtn = UIFactory.gButton(Language.getString(70336), -10, 30, 62, 22, this);
            this._enterBtn.visible = false;
            this._sweepBtn.visible = false;
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onItemOper);
            this._sweepBtn.configEventListener(MouseEvent.CLICK, this.onItemOper);
            this.configEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.graphics.clear();
            this._maxStar = 0;
            this._data = null;
            this._effectPlayer = null;
            this._isActivate = false;
            this._isLoadCompl = false;
            this._point.dispose(param1);
            this._enterBtn.dispose(param1);
            this._sweepBtn.dispose(param1);
            this._point = null;
            this._enterBtn = null;
            this._sweepBtn = null;
            ToolTipsManager.unregister(this);
            return;
        }// end function

    }
}
